<template>
  <section class="main">
    <input v-model="isAll" id="toggle-all" class="toggle-all" type="checkbox" />
    <label for="toggle-all">Mark all as complete</label>
    <ul class="todo-list">
      <li v-for="item in list" :key="item.id" :class="{ completed: item.isDone }">
        <div class="view">
          <input @change="hChange(item.id)" class="toggle" type="checkbox" :checked="item.isDone" />
          <label>{{ item.name }}</label>
          <button @click="hDel(item.id)" class="destroy"></button>
        </div>
      </li>
    </ul>
  </section>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true
    }
  },
  methods: {
    hDel(id) {
      this.$emit('delTask', id)
    },
    hChange(id) {
      this.$emit('changeState', id)
    }
  },
  computed: {
    isAll: {
      set(val) {

        this.$emit('changeAll', val)
      },
      get() {
        return this.list.every(item => item.isDone)
      } 
    }
  }
}
</script>

<style>

</style>